package com.atguigu.tingshu.executor;

import com.atguigu.tingshu.search.service.SearchService;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
public class SearchJobExecutor {
    @Autowired
    SearchService searchService;
    private static Logger logger = LoggerFactory.getLogger(SearchJobExecutor.class);

    //更新排行榜: 1小时更新一次
    @XxlJob("updateRankingJobHandler")//
    public void updateRankingJobHandler(){
        logger.info("开始更新排行榜：{}" , new Date());
        //把控制台日志保持到xxl-job日志
        XxlJobHelper.log("开始更新排行榜：{}" , new Date());
        searchService.updateLatelyAlbumRanking();
        logger.info("更新排行榜成功：{}" , new Date());
        XxlJobHelper.log("更新排行榜成功：{}", new Date());

    }
}
